package org.sdnstproject.interlayer.openflowfuzzing;

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;

public class Configuration {
	private String controllerIP;
	private String controllerPasswd;
	private String controllerUser;
	private String switchIP;
	private String switchPasswd;
	private String switchUser;
	private String localIP;
	private int interlayerPort;
	private int controllerPort;
	private int switchNumber;
	private String targetController;
	public Properties properties;
	private String[] prope = {"controllerIP","controllerPasswd","controllerUser","switchIP","switchPasswd",
								"switchUser","localIP","interlayerPort","controllerPort","switchNumber","targetController"};
	
	
	private static final Configuration instance = new Configuration();
    protected Configuration() {
    	initialize();
    }
    public static Configuration getInstance() {
        return instance;
    }
    
    public void initialize() {
    	Properties properties = new Properties();
    	FileInputStream fileInputStream;
    	try {
    		fileInputStream = new FileInputStream("./src/main/java/config.properties");
    		properties.load(fileInputStream);
    		this.properties = properties;
    	}catch (Exception e) {
    		e.printStackTrace();
		}
    	
    	for(String string:prope) {
    		if(!properties.containsKey(string)) continue;
    		switch (string) {
			case "controllerIP":
				setControllerIP(properties.getProperty(string));
				break;
			case "controllerPasswd":
				setControllerPasswd(properties.getProperty(string));
				break;
			case "controllerUser":
				setControllerUser(properties.getProperty(string));
				break;
			case "switchIP":
				setSwitchIP(properties.getProperty(string));
				break;
			case "switchPasswd":
				setSwitchPasswd(properties.getProperty(string));
				break;
			case "switchUser":
				setSwitchUser(properties.getProperty(string));
				break;
			case "localIP":
				setLocalIP(properties.getProperty(string));
				break;
			case "interlayerPort":
				setInterlayerPort(properties.getProperty(string));
				break;
			case "controllerPort":
				setControllerPort(properties.getProperty(string));
				break;
			case "switchNumber":
				setSwitchNumber(properties.getProperty(string));
				break;
			case "targetController":
				setTargetController(properties.getProperty(string));
				break;
		}
    		
    	}
    }
	public String getControllerIP() {
		return controllerIP;
	}
	public void setControllerIP(String controllerIP) {
		this.controllerIP = controllerIP;
	}
	public String getControllerPasswd() {
		return controllerPasswd;
	}
	public void setControllerPasswd(String controllerPasswd) {
		this.controllerPasswd = controllerPasswd;
	}
	public String getControllerUser() {
		return controllerUser;
	}
	public void setControllerUser(String controllerUser) {
		this.controllerUser = controllerUser;
	}
	public String getSwitchIP() {
		return switchIP;
	}
	public void setSwitchIP(String switchIP) {
		this.switchIP = switchIP;
	}
	public String getSwitchPasswd() {
		return switchPasswd;
	}
	public void setSwitchPasswd(String switchPasswd) {
		this.switchPasswd = switchPasswd;
	}
	public String getSwitchUser() {
		return switchUser;
	}
	public void setSwitchUser(String switchUser) {
		this.switchUser = switchUser;
	}
	public String getLocalIP() {
		return localIP;
	}
	public void setLocalIP(String localIP) {
		this.localIP = localIP;
	}
	public int getInterlayerPort() {
		return interlayerPort;
	}
	public void setInterlayerPort(String interlayerPort) {
		this.interlayerPort = Integer.parseInt(interlayerPort);
	}
	public int getControllerPort() {
		return controllerPort;
	}
	public void setControllerPort(String controllerPort) {
		this.controllerPort = Integer.parseInt(controllerPort);
	}
	public int getSwitchNumber() {
		return switchNumber;
	}
	public void setSwitchNumber(String switchNumber) {
		this.switchNumber = Integer.parseInt(switchNumber);
	}
	public String getTargetController() {
		return targetController;
	}
	public void setTargetController(String targetController) {
		this.targetController = targetController;
	}
	@Override
	public String toString() {
		return "Configuration [controllerIP=" + controllerIP + ", controllerPasswd=" + controllerPasswd
				+ ", controllerUser=" + controllerUser + ", switchIP=" + switchIP + ", switchPasswd=" + switchPasswd
				+ ", switchUser=" + switchUser + ", localIP=" + localIP + ", interlayerPort=" + interlayerPort
				+ ", controllerPort=" + controllerPort + ", switchNumber=" + switchNumber + "]";
	}
	
	/*switch (string) {
				case "controllerIP":
					setControllerIP(properties.getProperty(string));
					break;
				case "controllerPasswd":
					setControllerPasswd(properties.getProperty(string));
					break;
				case "controllerUser":
					setControllerUser(properties.getProperty(string));
					break;
				case "switchIP":
					setSwitchIP(properties.getProperty(string));
					break;
				case "switchPasswd":
					setSwitchPasswd(properties.getProperty(string));
					break;
				case "switchUser":
					setSwitchUser(properties.getProperty(string));
					break;
				case "localIP":
					setLocalIP(properties.getProperty(string));
					break;
				case "interlayerPort":
					setInterlayerPort(properties.getProperty(string));
					break;
				case "controllerPort":
					setControllerPort(properties.getProperty(string));
					break;
				case "switchNumber":
					setSwitchNumber(properties.getProperty(string));
					break;
			}
	 * */
    
	/*Iterator<Entry<Object,Object>> iterator = properties.entrySet().iterator();
    		while(iterator.hasNext()) {
	 * switch (iterator.next().getKey().toString()) {
					case "controllerIP":
						this.controllerIP = (String) iterator.next().getValue();
//						setControllerIP(iterator.next().getValue().toString());
						break;
					case "controllerPasswd":
						this.controllerPasswd = (String) iterator.next().getValue();
//						setControllerPasswd(properties.getProperty(string));
						break;
					case "controllerUser":
						this.controllerUser = (String) iterator.next().getValue();
//						setControllerUser(properties.getProperty(string));
						break;
					case "switchIP":
						this.switchIP = (String) iterator.next().getValue();
//						setSwitchIP(properties.getProperty(string));
						break;
					case "switchPasswd":
						this.switchPasswd = (String) iterator.next().getValue();
//						setSwitchPasswd(properties.getProperty(string));
						break;
					case "switchUser":
						this.switchUser = (String) iterator.next().getValue();
//						setSwitchUser(properties.getProperty(string));
						break;
					case "localIP":
						this.localIP = (String) iterator.next().getValue();
//						setLocalIP(properties.getProperty(string));
						break;
					case "interlayerPort":
						this.interlayerPort = (int) iterator.next().getValue();
//						setInterlayerPort(properties.getProperty(string));
						break;
					case "controllerPort":
						this.controllerPort = (int) iterator.next().getValue();
//						setControllerPort(properties.getProperty(string));
						break;
					case "switchNumber":
						this.switchNumber = (int) iterator.next().getValue();
//						setSwitchNumber(properties.getProperty(string));
						break;
				}
	 * */
    
}
